<template>
	<view class="center">
		<view class="center-header">
			<view class="center-header-imgBox" v-if="store.userInfo.avatar" @click="clickImg">
				<image :src="imgSrc"></image>
			</view>
			<view class="center-header-imgBox" v-else>头像</view>
			<view class="center-header-userName">{{store.userInfo.nickName}}</view>
		</view>
		<view class="center-main">
			<view class="center-main-item" @click="goQuit">
				<view class="center-main-item-name">退出登录</view>
				<view><up-icon name="arrow-right" color="#000" size="21"></up-icon></view>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		ref,
		onMounted
	} from 'vue'
	import {
		userInfoStore
	} from "@/stores/index.js"
	import {
		baseurl
	} from '@/utils/config.js'
	const store = userInfoStore()
	const imgSrc = ref('')
	const clickImg = () => {
		console.log('1111111',imgSrc.value)
		uni.previewImage({
			urls: [imgSrc.value], //多张的时候加，
			current: "", // 点击后显示的图片路径，默认是第一个
			success: function(res) {},
			fail: function(res) {},
			complete: function(res) {},
		})

	}
	const goQuit = () => {
		uni.showModal({
			title: "确认退出登录吗",
			content: "",
			confirmText: "确定",
			showCancel: true,
			success: (res) => {
				if (res.confirm) {
					uni.showLoading();
					uni.hideLoading()
					uni.removeStorageSync('token');
					uni.navigateTo({
						url: "/pages/login/login"
					})
				}
			}
		})

	}
	onMounted(() => {
		imgSrc.value = `${baseurl}prod-api${store.userInfo.avatar}` ?
			`${baseurl}prod-api${store.userInfo.avatar}` : '../../static/nosrc.png'
	})
</script>
<style>
	page {
		background: #F6F6F6;
	}
</style>
<style lang="scss">
	.center {
		&-header {
			width: 100%;
			height: 186rpx;
			background: #FFFFFF;
			box-shadow: 0rpx 2rpx 4rpx 2rpx rgba(0, 0, 0, 0.16);
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 40rpx 32rpx;
			box-sizing: border-box;

			&-imgBox {
				width: 106rpx;
				height: 106rpx;
				border-radius: 50%;
				border: 1rpx solid #000;
				color: #000;
				text-align: center;
				line-height: 106rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}

			&-userName {
				color: #333;
				font-size: 32rpx;
				font-weight: 550;
			}
		}

		&-main {
			margin-top: 12rpx;

			&-item {
				padding: 20rpx 32rpx;
				box-sizing: border-box;
				width: 100%;
				height: 80rpx;
				background-color: #FFFFFF;
				display: flex;
				align-items: center;
				justify-content: space-between;

				&-name {
					font-size: 28rpx;
					color: #333;
				}
			}
		}
	}
</style>